<template>
  <div id="app">
    <keep-alive include="imgDetail">
      <router-view />
    </keep-alive>
  </div>
</template>

<script>
  import Cookies from 'js-cookie'
export default {
  name: 'App',
    mounted() {
      window.addEventListener("beforeunload", (e) => this.beforeunloadHandler(e));
      window.addEventListener("unload", (e) => this.unloadHandler(e));
    },
    destroyed() {
      window.removeEventListener("beforeunload", (e) =>this.beforeunloadHandler(e));
      window.removeEventListener("unload", (e) => this.unloadHandler(e));
    },
  methods: {
    beforeunloadHandler() {
      this.beforeUnload_time = new Date().getTime();
    },
    unloadHandler(e) {
      this.gap_time = new Date().getTime() - this.beforeUnload_time;
      //判断是窗口关闭还是刷新
      if (this.gap_time <= 5) {
      let num = Cookies.get("window_number");
      num--;
      Cookies.set("window_number",num);
      
      }
    },
  }

}
</script>
